// AsyncIOManager.h
#pragma once
#include <Windows.h>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>

struct IORequest {
    enum Type { READ, WRITE } type;
    std::wstring path;
    std::vector<uint8_t> buffer;
    size_t offset;
    size_t length;
    std::function<void(NTSTATUS)> callback;
};

class AsyncIOManager {
public:
    AsyncIOManager(size_t threadCount = 4);
    ~AsyncIOManager();

    // 提交异步读请求
    void QueueRead(const std::wstring& path, std::vector<uint8_t>& buffer,
                  size_t offset, size_t length,
                  std::function<void(NTSTATUS)> callback);

    // 提交异步写请求
    void QueueWrite(const std::wstring& path, const std::vector<uint8_t>& buffer,
                   size_t offset, std::function<void(NTSTATUS)> callback);

private:
    void WorkerThread();
    void ProcessRequest(IORequest& req);

    std::vector<std::thread> m_workers;
    std::queue<IORequest> m_pendingRequests;
    std::mutex m_mutex;
    std::condition_variable m_condition;
    bool m_shutdown;
};